﻿--[[
   @brief    descprtion
   @author   rickonzhang
   @version  1.0
   @date     2015-06-10
--]]
group_menu_control = 
{
    CANCLE_FORBID_MSG = 0;
    FORBID_MSG = 2;

    init = function()
        base_utility.log("group_menu_control init")
    end;

    show = function(event_id, json_str)
        ierd_tgp.tpf_ui.Require("social\\group_menu\\view.lua");
        ierd_tgp.tpf_ui.Require("social\\talk_dialog\\control.lua");
        local param = base_utility.json_to_table(json_str)
        group_menu_view.show(true, param["group_id"])
        group_menu_view.move(param["x"], param['y'])
    end;  

    delete_group = function(group_id)
        local social_network =
            base_utility.get_component_adapter("ISocial_network",
                "ierd_tgp.social_network.Get_social_network_adapter();");
        if social_network then
            local group_str = NewStr(200);
            group_str = group_id;
            social_network:delete_group(group_str);
        end
    end;

    quit_group = function(group_id, quiter)
        local social =
            base_utility.get_component_adapter("ISocial_network",
                "ierd_tgp.social_network.Get_social_network_adapter();");
        social:quit_group(group_id, quiter);
    end;

    mask_group_message = function(action, group_id)
        --先更新屏蔽标注，如果mask_group_message_rsp 返回失败，在修改回来
        group_list_model.update_group_mask_msg_flag(group_id, action);
        talk_dialog_control.update_group_mask_msg_flag(group_id, action);

        local social =
            base_utility.get_component_adapter("ISocial_network",
                "ierd_tgp.social_network.Get_social_network_adapter();");
        social:mask_group_message(action, group_id, login_model.im_login_infomation["friend_id"]);
    end;

    mask_group_message_rsp = function(event_id, json_str)
        local p_tbl = base_utility.json_to_table(json_str);
        base_utility.log("[mask_group_message_rsp] result:"..p_tbl["result"]..", group_id:"..p_tbl["group_id"]);
        if p_tbl["result"] == 0 then
            -- do nothing
            base_utility.log("[mask_group_message_rsp]update result success");
        else
            --更新失败，修改回去
            local c_flag = group_list_model.get_group_mask_msg_flag(p_tbl["group_id"]);
            if c_flag == group_menu_control.CANCLE_FORBID_MSG then
                c_flag = group_menu_control.FORBID_MSG;
            else
                c_flag = group_menu_control.CANCLE_FORBID_MSG;
            end
            group_list_model.update_group_mask_msg_flag(p_tbl["group_id"], c_flag);
            ierd_tgp.tpf_ui.Require("social\\talk_dialog\\control.lua")
            talk_dialog_control.update_group_mask_msg_flag(p_tbl["group_id"], c_flag);
        end
    end;
};

group_menu_control.init();